$(document).ready(function(){
    function getOrderList(p,status){
        getAjax(global.apiUrl+'/get_shop_order',function(res){
            $("#page").paging({
                pageNo:p,
                totalPage: Math.ceil(res.count/20),
                totalSize: res.count,
                callback: function(num) {
                    getOrderList(num,status)
                }
            });
            res.content = res.content.reverse();
            var html = '';
            for(var i=0; i<res.content.length;i++){
                html += `
                     <tr>
                        <!-- <td>
                             <input type="checkbox" class="i-checks is-checked" name="input[]" value="${res.content[i].id}" >
                         </td>-->
                        <td>
                            <div class="vip-name-box">
                                <!--<div class="vip-head-img" style="background: url('../img/shop/tac-details02.jpg') no-repeat center center /cover"></div>-->
                                <div class="vip-name">${res.content[i].name}</div>

                            </div>
                        </td>
                        <td>${res.content[i].phone}</td>
                        <td>${timeStampToTime(res.content[i].paytime)}</td>
                        <td>
                            ${res.content[i].order_num}
                        </td>
                        <td>
                            积分支付
                        </td>
                        <td>

                            ${res.content[i].order_jf} 积分
                        </td>
                        <td>
                            <div>
                                <i class="fa fa-truck iconfont wl" title="物流信息" data-id="${res.content[i].id}"></i>
                                <i class="glyphicon glyphicon-file iconfont orderDetails" title="订单详情" data-id="${res.content[i].id}"></i>
                            </div>
                        </td>
                        <td>
                            <button class="btn
                            ${orderStatusStyle(res.content[i].status)}
                            btn-sm">${orderStatus(res.content[i].status)}</button>
                        </td>
                    </tr>
                `
            }
            $('#order-list').html(html);
        },{p:p,status:status});
    }
    //status 4未支付  1已支付未发货 2已支付已收货   3已支付已发货  获取订单列表 fun
    var p = 1;
    var status;
    $('.order-nav').on('click','li',function(){
        $('.order-nav li').removeClass('active');
        $(this).addClass('active');
        var $status = $(this).data('status');
        status = $status;
        getOrderList(p,status);
    });
    getOrderList(p,status);
    var selectItem = new Array();
    $('#btn').click(function(){
        var isChecked = document.getElementsByClassName('is-checked');
        for(var i=0; i<isChecked.length;i++){
            if(isChecked[i].checked==true){
                selectItem.push(isChecked[i].value);
            }
        }
        console.log(selectItem);
    })
    $('#selectAll').on('click',function(){
        var isChecked = document.getElementsByClassName('is-checked');
        var selectAll = document.getElementById('selectAll');
        if(selectAll.checked == true){
            for(var i=0; i<isChecked.length;i++){
                isChecked[i].checked=true;
            }
        }else if(selectAll.checked==false){
            for(var i=0; i<isChecked.length;i++){
                isChecked[i].checked=false;
            }
        }
    })

    //搜索事件
    $('#searchBtn').on('click',function(){
        var name,phone,orderNum;
        console.log($('#searchKey option:selected').val());
        switch ($('#searchKey option:selected').val()) {
            case '0': alert('请选择查询字段！'); break;
            case '1': name = $('#searchContent').val();break;
            case '2': phone = $('#searchContent').val();break;
            case '3': orderNum = $('#searchContent').val();break;
        }
        console.log(name,phone,orderNum);
        searchOrderList(p,status,name,phone,orderNum);
    })

    //搜索功能
    function searchOrderList(p,status,name,phone,orderNum){
        getAjax(global.apiUrl+'/get_shop_order',function(res){
            $("#page").paging({
                pageNo:p,
                totalPage: Math.ceil(res.count/20),
                totalSize: res.count,
                callback: function(num) {
                    searchOrderList(num,status,name,phone,orderNum)
                }
            });
            res.content = res.content.reverse();
            var html = '';
            for(var i=0; i<res.content.length;i++){
                html += `
                     <tr>
                        <!-- <td>
                             <input type="checkbox" class="i-checks is-checked" name="input[]" value="${res.content[i].id}" >
                         </td>-->
                        <td>
                            <div class="vip-name-box">
                                <!--<div class="vip-head-img" style="background: url('../img/shop/tac-details02.jpg') no-repeat center center /cover"></div>-->
                                <div class="vip-name">${res.content[i].name}</div>

                            </div>
                        </td>
                        <td>${res.content[i].phone}</td>
                        <td>${timeStampToTime(res.content[i].paytime)}</td>
                        <td>
                            ${res.content[i].order_num}
                        </td>
                        <td>
                            积分支付
                        </td>
                        <td>

                            ${res.content[i].order_jf} 积分
                        </td>
                        <td>
                            <div>
                                <i class="fa fa-truck iconfont wl" title="物流信息" data-id="${res.content[i].id}"></i>
                                <i class="glyphicon glyphicon-file iconfont orderDetails" title="订单详情" data-id="${res.content[i].id}"></i>
                            </div>
                        </td>
                        <td>
                            <button class="btn
                            ${orderStatusStyle(res.content[i].status)}
                            btn-sm">${orderStatus(res.content[i].status)}</button>
                        </td>
                    </tr>
                `
            }
            $('#order-list').html(html);
        },{p:p,status:status,name:name,phone:phone,order_num:orderNum});
    }














})
